import {
  Count,
  CountSchema,
  Filter,
  FilterExcludingWhere,
  repository,
  Where,
} from '@loopback/repository';
import {
  del,
  get,
  getModelSchemaRef,
  param,
  patch,
  post,
  put,
  requestBody,
  response,
} from '@loopback/rest';
import {Employ} from '../models';
import {EmployRepository} from '../repositories';

export class TestController {
  constructor(
    @repository(EmployRepository)
    public employRepository: EmployRepository,
  ) { }

  @post('/employs')
  @response(200, {
    description: 'Employ model instance',
    content: {'application/json': {schema: getModelSchemaRef(Employ)}},
  })
  async create(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Employ, {
            title: 'NewEmploy',
            exclude: ['id'],
          }),
        },
      },
    })
    employ: Omit<Employ, 'id'>,
  ): Promise<Employ> {
    return this.employRepository.create(employ);
  }

  @get('/employs/count')
  @response(200, {
    description: 'Employ model count',
    content: {'application/json': {schema: CountSchema}},
  })
  async count(
    @param.where(Employ) where?: Where<Employ>,
  ): Promise<Count> {
    return this.employRepository.count(where);
  }

  @get('/employs')
  @response(200, {
    description: 'Array of Employ model instances',
    content: {
      'application/json': {
        schema: {
          type: 'array',
          items: getModelSchemaRef(Employ, {includeRelations: true}),
        },
      },
    },
  })
  async find(
    @param.filter(Employ) filter?: Filter<Employ>,
  ): Promise<Employ[]> {
    return this.employRepository.find(filter);
  }

  @patch('/employs')
  @response(200, {
    description: 'Employ PATCH success count',
    content: {'application/json': {schema: CountSchema}},
  })
  async updateAll(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Employ, {partial: true}),
        },
      },
    })
    employ: Employ,
    @param.where(Employ) where?: Where<Employ>,
  ): Promise<Count> {
    return this.employRepository.updateAll(employ, where);
  }

  @get('/employs/{id}')
  @response(200, {
    description: 'Employ model instance',
    content: {
      'application/json': {
        schema: getModelSchemaRef(Employ, {includeRelations: true}),
      },
    },
  })
  async findById(
    @param.path.number('id') id: number,
    @param.filter(Employ, {exclude: 'where'}) filter?: FilterExcludingWhere<Employ>
  ): Promise<Employ> {
    return this.employRepository.findById(id, filter);
  }

  @patch('/employs/{id}')
  @response(204, {
    description: 'Employ PATCH success',
  })
  async updateById(
    @param.path.number('id') id: number,
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Employ, {partial: true}),
        },
      },
    })
    employ: Employ,
  ): Promise<void> {
    await this.employRepository.updateById(id, employ);
  }

  @put('/employs/{id}')
  @response(204, {
    description: 'Employ PUT success',
  })
  async replaceById(
    @param.path.number('id') id: number,
    @requestBody() employ: Employ,
  ): Promise<void> {
    await this.employRepository.replaceById(id, employ);
  }

  @del('/employs/{id}')
  @response(204, {
    description: 'Employ DELETE success',
  })
  async deleteById(@param.path.number('id') id: number): Promise<void> {
    await this.employRepository.deleteById(id);
  }
}
